	//规则, 组件名字驼峰, 元素标签中划线分割, 两者映射缺一不可.
angular.module('app').component('winitEditTable', {
		templateUrl: getTemplateUrl('matrix/component/tpl/winitEditTable.html'),
		bindings: {
			thdata:'<',
			data:"<",
			saveBlur: '&',
        	deleteBlur: '&',
        	trcheckBlur: '&'
		},
		controller: function ($scope, $element,$http,$filter, $attrs,$rootScope){
			var ctrl = this;
			console.log(ctrl)
			ctrl.save=function(info){
				console.log(info)
				ctrl.saveBlur({
					info:info
				})
			}
			ctrl.remove=function(index){
				var info = {};
	            info.titleData = "提示";
	            info.bodyData = "确定要删除该配置项么吗？";
	            $rootScope.confirmWindow(info, function () {
	            	ctrl.deleteBlur({
	            		info:ctrl.data.datas[index]
	            	})
	                ctrl.data.datas.splice(index, 1);
	            });
			}
			ctrl.onshow=function(config){
				if(!config.checkTrue || config.checkTrue==undefined){
					config.checkTrue=true
				}
			}
			ctrl.onhide=function(config){
				if(config.checkTrue || config.checkTrue==undefined){
					config.checkTrue=false
				}
			}

			ctrl.selectShow=function(info,typeList,typeKey,typeValue){
				if(info && typeList.length) {
					var selected=[];
					angular.forEach(typeList, function(type){
						if(type[typeKey]==info){
							 selected.push(type);
						}
					})
                    // var selected = $filter('filter')(typeList, {key: info});
                    return selected.length ? selected[0][typeValue] : 'empty';
                } else {
                    return info || 'empty';
                }
			}

			//tr行选中事件
	        ctrl.trcheck = function (info) {
	        	if(info.checkTrue){
	        		return;
	        	}
	            var i = "";
	            if (!info.trCheck || info.trCheck == undefined) {
	                i = info;
	                angular.forEach(ctrl.data.datas, function (c) {
	                    c.trCheck = false;
	                    c.color = "";
	                });
	                info.trCheck = true;
	                info.color = "sky";
	            } else {
	                info.trCheck = false;
	                info.color = "";
	            }
	            ctrl.trcheckBlur({
	                info: i
	            });
	        };
		
      	}
});
